<?php
/**
 * 接口调用次数查询
 */
require 'vendor/autoload.php';

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Exception\RequestException;

use GuzzleHttp\Promise;

$GLOBALS['appID'] = "0988E21B01B60906678E6C169A2699AD";
$GLOBALS['appKey'] = '1088957707187519101';
$GLOBALS['url'] = 'https://area42-win.pospal.cn:443/';

function get_post($url, $data, $headers)
{
    $client = new Client();
    try {
        $response = $client->post($GLOBALS['url'] . $url, [
            'headers' => $headers,
            'json' => $data
        ]);
        // 输出请求结果
        return $response->getBody();
    } catch (RequestException $e) {
        // 输出请求异常
        return $e->getMessage();
    }
}
$startTime = $_POST['startTime'];
$endTime = $_POST['endTime'];
$body = [
    "appId" => $GLOBALS['appID'],
    "beginDate" => date('Y-m-d', strtotime("-1 day")),
    "endDate" => date('Y-m-d', strtotime("+1 day")),
];

$headers = [
    'User-Agent' => 'openApi',
    'Content-Type' => 'application/json',
    'data-signature' => strtoupper(md5($GLOBALS['appKey'] . json_encode($body)))
];
$res = json_decode(get_post('pospal-api2/openapi/v1/openApiLimitAccess/queryDailyAccessTimesLog', $body, $headers));
// die(var_dump($res));
die(json_encode([
    "code" => 0,
    "msg" => "success",
    "data" => $res
]));